﻿using log4net.Core;
using Modules.System.Dept;
using PmSoft;
using PmSoft.Entity;
using System.Xml.Linq;
using static Modules.Project.ProjectConstants;

namespace Modules.System.User;

public class DeptUser : IDeptUser
{
    /// <summary>
    /// 用户名
    /// </summary>
    public string Name { get; set; }
    /// <summary>
    /// 用户ID
    /// </summary>
    public int Id { get; set; }
    /// <summary>
    /// 信息安全Id
    /// </summary>
    public int SecurityId { get; set; }
    /// <summary>
    /// 登陆类型
    /// </summary>
    public UserType Type { get; set; }

    /// <summary>
    /// 归属省代码
    ///</summary>
    public int? ProvinceCode { get; set; }
    /// <summary>
    /// 归属地市代码
    ///</summary>
    public int? CityCode { get; set; }

    /// <summary>
    /// 所属单位
    /// </summary>
    public int? DeptId { get; set; }

    /// <summary>
    /// 归属区县代码
    ///</summary>
    public int? AreaCode { get; set; }
    /// <summary>
    /// 行业分类
    /// </summary>
    public 行业主管部门 IndustryType { get; set; }
    /// <summary>
    /// 行政级别 1：部、2：省、3：市、4：县
    ///</summary>
    public AdministrativeLevel Level { get; set; }
}

public static partial class SysUserExtensions
{
    public static IDeptUser AsDeptUser(this SysUser user, SysDept dept)
    {
        return new DeptUser
        {
            Id = user.UserId,
            Name = user.Name,
            SecurityId = user.SecurityId,
            Type = UserType.SysUser,
            ProvinceCode = dept.ProvinceCode,
            CityCode = dept.CityCode,
            DeptId = user.DeptId,
            AreaCode = dept.AreaCode,
            IndustryType = dept.IndustryType,
            Level = dept.Level
        };
    }

}